﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace ConsoleApp.Security
{
    public sealed class MD5Provider
    {
        public static string Encrypt(string input)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] resultEncrypt = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
            StringBuilder sb = new StringBuilder();
            foreach (var item in resultEncrypt)
            {
                sb.Append(item.ToString("x2"));
            }
            return sb.ToString();
        }

        public static string Encrypt(SortedDictionary<string, string> input)
        {
            StringBuilder sb = new StringBuilder();
            foreach (var item in input)
            {
                sb.Append(item.Key + "=" + item.Value + "&");
            }
            return Encrypt(sb.Remove(sb.Length - 1, 1).ToString());
        }
    }
}